import altair as alt
from back_end.hsa.data_display.keyword_trends import KeywordTrends

class LineChart:
    __time_range_map = {
        '周': (7, 1),
        '月': (10, 3),
        '年': (12, 30),
    }

    @staticmethod
    def plot(time_range):
        df = KeywordTrends(*LineChart.__time_range_map.get(time_range)).to_df()
        return LineChart.__get_line_chart(df)

    @staticmethod
    def __get_line_chart(df):
        return alt.Chart(df).mark_line().encode(
            x=alt.X('日期:N', title='日期', axis=alt.Axis(labelAngle=-45)),
            y=alt.Y('数量:Q', title='词汇数量'),
            color='词汇:N',
            tooltip=['词汇', '数量', '日期']
        ).properties(width=1000, height=400)
